import { Space, Divider } from 'antd'
import { formatDate } from '@src/assets/js/tool'
import { CaseSchema } from '@src/components/schema/caseSchema'
import { ColumnsType } from 'antd/es/table'
import { History } from 'history'
import Serieno from '@src/pages/admin/components/serieno'
import { Dispatch } from 'redux'
import { addWindow } from '@src/redux/actions/tab'

export function getColumn (dispatch: Dispatch, performanceType: '受理' | '办案'): ColumnsType<CaseSchema> {
  const isAccepter = performanceType === '受理'
  const columns: ColumnsType<CaseSchema> = [
    {
      title: '序号',
      dataIndex: 'orderno',
      key: 'orderno',
      width: 80
    },
    {
      title: isAccepter ? '受理秘书' : '办案秘书',
      dataIndex: isAccepter ? 'accepter' : 'processer',
      key: isAccepter ? 'accepter' : 'processer'
    },
    {
      title: '案号',
      dataIndex: 'caseno_desc',
      key: 'caseno_desc',
      render: (v: string, l: CaseSchema) => {
        return (
          <span>
            <span>{v}</span>
            <Serieno data={l} />
          </span>
        )
      }
    },
    {
      title: '收案时间',
      dataIndex: 'accept_datetime',
      key: 'accept_datetime',
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YY.MM.DD')
        }
      }
    },
    {
      title: '结案时间',
      dataIndex: 'closure_datetime',
      key: 'closure_datetime',
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YY.MM.DD')
        }
      }
    },
    {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      render: (v: string, l: CaseSchema) => {
        return (
          <Space split={<Divider type="vertical" />}>
            <a onClick={() => { dispatch(addWindow({ id: `case-assess-${v}`, title: `${l.caseno_desc}-绩效详情`, componentName: 'CaseAssess', meta: {id: v} })) }}>详情</a>
          </Space>
        )
      }
    }
  ]
  if (isAccepter) {
    columns.splice(5, 0, {
      title: '均值分',
      dataIndex: 'accepter_ratio_score',
      key: 'accepter_ratio_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    }, {
      title: '加分',
      dataIndex: 'accepter_positive_score',
      key: 'accepter_positive_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    }, {
      title: '扣分',
      dataIndex: 'accepter_positive_score',
      key: 'accepter_positive_score',
      render: (v: number, l: CaseSchema) => {
        const total: number = l.accepter_score
        if (typeof v === 'number' && typeof total === 'number') {
          return (total - v).toFixed(3)
        }
      }
    }, {
      title: '抽查分',
      dataIndex: 'accepter_score',
      key: 'accepter_score',
      render: (v: number, l: CaseSchema) => {
        if (typeof v === 'number' && typeof l.accepter_base_score === 'number') {
          return (v - l.accepter_base_score).toFixed(3)
        }
      }
    }, {
      title: '总分',
      dataIndex: 'accepter_score',
      key: 'accepter_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    })
  } else {
    columns.splice(5, 0, {
      title: '均值分',
      dataIndex: 'processer_ratio_score',
      key: 'processer_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    },
    {
      title: '加分',
      dataIndex: 'processer_positive_score',
      key: 'processer_positive_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    },
    {
      title: '扣分',
      dataIndex: 'processer_positive_score',
      key: 'processer_positive_score',
      render: (v: number, l: CaseSchema) => {
        const total: number = l.processer_score
        if (typeof v === 'number' && typeof total === 'number') {
          return (total - v).toFixed(3)
        }
      }
    }, {
      title: '抽查分',
      dataIndex: 'processer_score',
      key: 'processer_score',
      render: (v: number, l: CaseSchema) => {
        if (typeof v === 'number' && typeof l.processer_base_score === 'number') {
          return (v - l.processer_base_score).toFixed(3)
        }
      }
    },
    {
      title: '总分',
      dataIndex: 'processer_score',
      key: 'processer_score',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      }
    })
  }
  return columns
}
